Technical Field
The present invention relates generally to information processing and, in particular, to automatically enabling a read-only cache in a language in which two arrays in two different variables may alias each other.
Description of the Related Art
There are languages in which two arrays in two different variables may alias each other such as C and Java®. For example, in a sample program, a[ ] and b[ ] may point to the same array.
In computer programming, and as used herein, aliasing refers to the situation where the same memory location can be accessed using different names. Such a situation can be quite problematic, particularly in the case of sequential writes. For example, if two writes are aliased and occur out of sequence, an incorrect program result will likely occur. The same is true for a write access and a read access. In contrast, if two reads are aliased and occur out of sequence, the program result will likely not be affected.
A general purpose graphics processing unit (GPGPU) by NVIDIA® provides a read-only cache, which can be accessed fast, on a chip. This read-only cache is not coherent with write actions to other memory system. Thus, the read-only cache must be used only for accesses to memory that must not be written by the same GPU code.
The CUDA language provided by NVIDIA® allows a programmer to enable a read-only cache by decorating pointer arguments using “const_restrict_”, or using an intrinsic “_ldg( )” for each access. The Open Accelerators (OpenACC) programming standard does not allow a programmer to enable read-only cache explicitly.
TABLE 1 below shows a sample program written in Java®.
TABLE 1void test(int a[ ], int b[ ]) { IntStream.range(0, b.length).parallel( ).forEach(i -> {  a[i] = b[i] * 2;  a[i] = b[i] * 3; });}
In the sample program written in Java® (or in an equivalent program in C with an OpenACC directive), a read-only cache is not automatically enabled. This program has lexical variables that points to arrays, and it has one or more lexical variables that do not perform write operations to arrays. If a compiler naively generate a code from a parallel stream to enable read-only cache for accesses regarding b[ ] in the sample program, the code will not work correctly when a[ ] and b[ ] point to the same array.
Thus, there is a need for automatically enabling a read-only cache in a computer programming language in which two arrays in two different variables can alias each other.